package top.whysu.gps.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 定时器线程池管理类
 */
public class CronThreadPoolManager {

    private static final Logger LOGGER = LoggerFactory.getLogger(CronThreadPoolManager.class);
    private static Map<String, ExecutorService> threadPoolManager = new ConcurrentHashMap<>(100);

    public static synchronized ExecutorService getExecutorService(String className, String method) {
        String key = className + " " + method;
        ExecutorService executorService = threadPoolManager.get(key);
        if (executorService == null) {
            executorService = Executors.newSingleThreadExecutor();
            threadPoolManager.put(key, executorService);
        }
        LOGGER.debug("{},{}", key, executorService);
        return executorService;
    }
}
